package com.ebo.httpcall4j.core;

import com.ebo.httpcall4j.core.model.HttpCallRequest;
import com.ebo.httpcall4j.core.model.HttpCallResponse;
import com.ebo.httpcall4j.core.processor.HttpCallProcessor;

import java.io.IOException;
import java.util.concurrent.CompletableFuture;

/**
 * http静态调用工具类
 */
public class HttpCall {

    public static HttpCallResponse execute(HttpCallRequest request, Class<? extends HttpCallProcessor> processorClass) throws IOException {
        return getHttpCallService().call(request, processorClass);
    }

    public static CompletableFuture<HttpCallResponse> executeAsync(HttpCallRequest request, Class<? extends HttpCallProcessor> processorClass) {
        return getHttpCallService().callAsync(request, processorClass);
    }

    private static HttpCallService getHttpCallService() {
        return ApplicationContextHolder.getBean(HttpCallService.class);
    }
}